<?php

/**
 * 入库状态
 * @copyright   Copyright (c) 2006 - 2010 DZH 友拓软件友拓通
 * @category    采购
 * @package   Status
 * @author     庄敏学
 * @version  2.1,2012-07-22
 */

class InstockPublicStatus extends Status {
	
	/**
	 * 开发票 更新入库单状态 invoice_state
	 * @param array $params
	 */
	public function invoice($params){
		//新增时 如果是从入库单导入的  需更新入库单 状态
		if(ACTION_NAME=='insert'&&$params['relation_id']>0){
			if(C('invoice.factory_from')==1){
				M('instock_detail')->where("instock_id='".$params['relation_id']."' and factory_id='".$params['factory_id']."'")->setField('invoice_state',2);
			}else{
				M('instock_detail')->where("instock_id='".$params['relation_id']."'")->setField('invoice_state',2);
			}
		}
		//删除后 还原入库单的 invoice_state
		if(ACTION_NAME=='delete'){
			$info	= M('invoice_in_del')->find($params['id']);
			if($info['relation_id']>0){
				if(C('invoice.factory_from')==1){
					M('instock_detail')->where("instock_id='".$info['relation_id']."' and factory_id='".$info['factory_id']."'")->setField('invoice_state',1);
				}else{
					M('instock_detail')->where("instock_id='".$info['relation_id']."'")->setField('invoice_state',1);
				}
			}
		}
	}
}